package com.java.comprehensive;

import lombok.Data;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;

/**
 * @program: comprehensive-service
 *
 * @description:
 *
 * @author: 窦绍飞
 *
 * @create: 2021-12-01 13:53
 **/
public class ZhihuTest3 {


    private static String MAN = "man";
    private static String WOMAN = "woman";
    @Data
    static class Person{
        private String gender;
        private String name;

        private static Map<String, Consumer<String>> FUNC_MAP = new ConcurrentHashMap<>();
        static {
            FUNC_MAP.put(MAN,person ->{System.out.println(person + "应该去男厕所");});
            FUNC_MAP.put(WOMAN,person ->{System.out.println(person + "应该去女厕所");});
        }
        public void goToWC(){
            FUNC_MAP.get(gender).accept(name);
        }
    }

    static class PersonFactory{
        public static Person initPerson(String name ,String gender){
            Person p = new Person();
            p.setName(name);
            p.setGender(gender);
            return p;
        }
    }
    public static void main(String[] args) {
        Person p = PersonFactory.initPerson("张三",MAN);
        Person p2 = PersonFactory.initPerson("张三他老婆",WOMAN);
        p.goToWC();
        p2.goToWC();
    }


    //输出：
    //张三应该去男厕所
    //张三他老婆应该去女厕所
}
